import EventCenter from "../../TFrame/script/helper/EventCenter";
import EventNames from "../EventNames";
import DailyTaskSystem from "../system/DailyTaskSystem";

const {ccclass, property} = cc._decorator;

@ccclass
export default class ButtonDailyTask extends cc.Component {

    @property(cc.Node)
    redNode:cc.Node = null;

    start () {
        this.updateRedPoint();
        EventCenter.on(EventNames.DailyTaskGetReward, ()=>{
            this.updateRedPoint();
        }, this)
    }

    updateRedPoint() {
        let taskList = DailyTaskSystem.taskList;
        for(let i = 0; i < taskList.length; ++i) {
            if(DailyTaskSystem.isTaskGetRewarded(i) == 0 && taskList[i].isDone()) {
                this.redNode.active = true;
                return;
            }
        }
        this.redNode.active = false;
    }

}
